package logic

import (
	"context"
	"errors"
	"we-chat-mgr/models/mysql"

	"we-chat-mgr/wechatrpc/internal/svc"
	"we-chat-mgr/wechatrpc/wechatrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type WeChatMomentsDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewWeChatMomentsDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WeChatMomentsDelLogic {
	return &WeChatMomentsDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *WeChatMomentsDelLogic) WeChatMomentsDel(in *wechatrpc.WeChatMomentsDelRequest) (*wechatrpc.WeChatMomentsDelResponse, error) {
	// todo: add your logic here and delete this line

	var finduser mysql.User
	err := finduser.FindUserByUserId(mysql.DB, in.UserId)
	if err != nil {
		return nil, errors.New("用户不存在")
	}

	var wechatMomwnts mysql.WeChatMoments
	err = wechatMomwnts.DelWechatMoments(mysql.DB, in.UserId)
	if err != nil {
		return nil, err
	}

	return &wechatrpc.WeChatMomentsDelResponse{}, nil
}
